// SPDX-License-Identifier: GPL-2.0
/*
 * BUDDY GFP: GFP_PGTABLE_KERNEL
 *
 * (C) 2024.05.11 BuddyZhang1 <buddy.zhang@aliyun.com>
 */
#include <linux/init.h>
#include <linux/kernel.h>
#include <linux/module.h>
#include <linux/vmalloc.h>

#define VMEM_SIZE	(16 * 1024 * 1024)

static int __init BiscuitOS_init(void)
{
	void *mem;

	/* ALLOC PHYSICAL MEMORY AND
	 * ENABLE GFP_PGTABLE_KERNEL ON
	 * => vmap_pages_pte_range/pte_alloc_kernel_track */
	mem = vmalloc(VMEM_SIZE);

	/* ACCESS MEMORY */
	sprintf((char *)mem, "Hello BiscuitOS!");
	printk("%s\n", (char *)mem);

	/* RECLAIM */
	vfree(mem);

	return 0;
}

static void __exit BiscuitOS_exit(void) { }

module_init(BiscuitOS_init);
module_exit(BiscuitOS_exit);

MODULE_LICENSE("GPL");
MODULE_AUTHOR("BiscuitOS <buddy.zhang@aliyun.com>");
MODULE_DESCRIPTION("BUDDY ALLOCATOR ON BiscuitOS");
